package com.afkt.project.ui.adapter;


import com.afkt.project.model.bean.CommodityEvaluateBean;
import com.afkt.project.ui.widget.swipeaction.SwipeDirection;
import com.afkt.project.util.LogUtils;
import com.dev.DevUtils;
import com.dev.base.widget.BaseImageView;
import com.dev.base.widget.BaseTextView;
import com.dev.glide.utils.OhosGlide;
import com.dev.utils.common.BigDecimalUtils;
import com.dev.widget.ui.sliding.SwipeActionHelper;
import com.ohos.afkt.ResourceTable;
import ohos.agp.colors.RgbColor;
import ohos.agp.components.*;
import ohos.agp.components.element.ShapeElement;
import ohos.app.Context;
import ohos.multimodalinput.event.MmiPoint;
import ohos.multimodalinput.event.TouchEvent;

import java.io.IOException;
import java.math.BigDecimal;
import java.util.*;

public class GreenDaoAdapter extends BaseItemProvider {


    private List<CommodityEvaluateBean> data;

    private ListContainer mListContainer;

    private Context mContext;

    public GreenDaoAdapter(ListContainer mListContainer, List<CommodityEvaluateBean> data) {
        this.data = data;
        this.mListContainer=mListContainer;
        this.mContext = mListContainer.getContext();
    }



    @Override
    public int getCount() {
        return data.size();
    }

    @Override
    public Object getItem(int i) {
        return data.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public Component getComponent(int i, Component component, ComponentContainer componentContainer) {
        ViewHolder_select viewHolder = null;
        if (component ==null){
            component = LayoutScatter.getInstance(mContext).parse(ResourceTable.Layout_adapter_item_greendao,null,false);
            viewHolder = new ViewHolder_select();
            viewHolder.name = (BaseTextView) component.findComponentById(ResourceTable.Id_tv_name);
            viewHolder.content = (BaseTextView) component.findComponentById(ResourceTable.Id_tv_content);
            viewHolder.img1 = (BaseImageView) component.findComponentById(ResourceTable.Id_vid_tab1);
            viewHolder.img2 = (BaseImageView) component.findComponentById(ResourceTable.Id_vid_tab2);
            viewHolder.img3 = (BaseImageView) component.findComponentById(ResourceTable.Id_vid_tab3);
            viewHolder.img4 = (BaseImageView) component.findComponentById(ResourceTable.Id_vid_tab4);
            viewHolder.time = (BaseTextView) component.findComponentById(ResourceTable.Id_tv_time);
            viewHolder.linear = (DirectionalLayout) component.findComponentById(ResourceTable.Id_vid_ams_linear);
            component.setTag(viewHolder);
        }else {
            viewHolder = (ViewHolder_select) component.getTag();
        }

        // ===========
        // = 商品信息 =
        // ===========

        // 商品名
        viewHolder.name.setText(data.get(i).commodityName);
        // 商品价格
        viewHolder.content.setText("垃圾啊打开了放假啦看大家分厘卡机的法律可见度立刻就发绿卡的房间里咖啡角度来看打开了发觉看大家分厘卡甲方领导看");
        viewHolder.time.setText("2021.03.16");
        // 商品图片
        try {
            OhosGlide.with(DevUtils.getAbilitySlice()).load(data.get(i).commodityPicture).def(ResourceTable.Media_icon).into(viewHolder.img1);
            OhosGlide.with(DevUtils.getAbilitySlice()).load(data.get(i).commodityPicture).def(ResourceTable.Media_icon).into(viewHolder.img2);
            OhosGlide.with(DevUtils.getAbilitySlice()).load(data.get(i).commodityPicture).def(ResourceTable.Media_icon).into(viewHolder.img3);
            OhosGlide.with(DevUtils.getAbilitySlice()).load(data.get(i).commodityPicture).def(ResourceTable.Media_icon).into(viewHolder.img4);
        } catch (IOException e) {
            e.printStackTrace();
            LogUtils.error("OhosGlide",e.fillInStackTrace().getMessage());
        }
        return component;
    }




    public List<CommodityEvaluateBean> getData() {
        return data;
    }

    public void setData(List<CommodityEvaluateBean> data) {
        this.data = data;
    }


    static class ViewHolder_select {

        BaseTextView name;
        BaseTextView content;
        BaseImageView img1;
        BaseImageView img2;
        BaseImageView img3;
        BaseImageView img4;
        BaseTextView time;
        DirectionalLayout linear;
    }

}
